import { http } from '@/utils/http'
import type { HttpResultList } from '@/utils/http/types'

export interface UserRes {
  id: number
  /** 头像 */
  avatar: string
  /** 用户名 */
  username: string
  /** 昵称 */
  nickname: string
  /** 当前登录用户的角色 */
  // roles: Array<string>
  auth: number
}

export const registerUser = (data?: object) => {
  return http.request('post', '/api/users', { data })
}
export const getUserList = (query = { page: 1, 'page-size': 10 }) => {
  return http.request<HttpResultList<UserRes>>('get', '/api/users', {
    params: query
  })
}
export const getOnUser = (id: number) => {
  return http.request<UserRes>('get', `/api/users/${id}`)
}

export const getUserInfo = () => {
  return http.request<UserRes>('get', '/api/users/me')
}
export const updateUserAvatar = (data?: object) => {
  return http.request('put', '/api/users/me/avatar', { data })
}
export const updateUserPassword = (data?: object) => {
  return http.request('put', '/api/users/me/password', { data })
}
export const updateUserInfo = (data?: object) => {
  return http.request('put', '/api/users/me/info', { data })
}
